package com.itheima.admin.controller.v1;

import com.heima.model.common.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ChannelDTO;
import com.heima.model.common.dtos.ResponseResult;

import com.itheima.admin.service.AdChannelService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "频道管理", tags = "频道管理", description = "频道管理API")
@RestController
@RequestMapping("/api/v1/channel")
public class AdminController {
    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult list(@RequestBody ChannelDTO channelDTO) {
        return adChannelService.findByNameAndPage(channelDTO);
    }
    @PostMapping("/save")
    @ApiOperation("频道新增")
    public ResponseResult save(@RequestBody AdChannel adChannel){
        return adChannelService.insert(adChannel);
    }
    @PostMapping("/update")
    @ApiOperation("频道修改")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return adChannelService.update(adChannel);
    }
    @GetMapping("/del/{id}")
    @ApiOperation("频道删除")
    public ResponseResult delete(@PathVariable("id") Integer id){
        return adChannelService.delete(id);
    }
    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(adChannelService.getById(id));
    }


}
